clear
set more      off
set varabbrev off
set gr        off
set linesize 255

/* INPUTS */

local in_wages "/data2/cedsei/data2/wages" 		    // Produced in A3_search_RAMS_wwage
local in_ana   "/data2/cedsei/data2/analysis_sample_ww" // Produced in A5_analysis_prepare.do

/* OUTPUTS */

local out_anprep "/data2/cedsei/data2/analysis_prep"

*cd "/data2/cedsei/data2"

********************************************************************************

clear 
use if inrange(year,2004,2014) using `in_wages'
gcollapse (max) manl, by(lopnr year)
rename manl manl_l
replace year = year + 1 
save wages_l, replace 
replace year = year  - 2
save wages_f, replace 

clear 
use replacement_rate lopnr year daily_wage_normalized pes_se_0 workabs_* manl_* ///
search_* earnings_month_* if pes_se_0 == 1 using `in_ana'
merge m:1 lopnr year using wages_l 
drop if _merge==2
drop _merge
rename manl_l manl_l1
merge m:1 lopnr year using wages_f 
drop if _merge==2
drop _merge
rename manl_l manl_f1

gen search_ind = max(search_databa, search_direct, search_postads, search_recruit)
gen search_pes = cond(!mi(search_ext),cond(search_ext==1, cond(search_ind==0,1,0),0),.)
tab search_pes search_ind 

drop if mi(replacement_rate)
drop if replacement_rate>2

gen runvar = daily_wage_normalized
gen T = runvar*(runvar>0)
gen jump = runvar>0

save `out_anprep', replace 

